
var app = getApp();
const util = require('../../utils/util.js')
const config = require('../../utils/config.js');
var my = require("../../utils/request.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {

    //接口地址
    groupList: "groupon/mines",
    addToUser: "groupon/addToUser",
    gList: [],
    coupon_ZN: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 1500
    })
    var that = this
    that.groupList()
  },


  groupList: function () {

    var that = this;
    my.request({
      url: that.data.groupList,
      //data: params,
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        let curList = res.data.data;
        curList.forEach(item => {
          //转换中文类型
          item = item.detail
          let configs = {
            general_coupon: "优惠券",
            cash: "代金券",
            discount: "折扣券",
            gift: "兑换券",
            groupon: "团购券"
          }
          //  if (item.card.cart_type =="general_coupon"){
          //   // general_coupon();
          //  }
          // console.log(item.card.cart_type);
          item.card.cart_typezh = configs[item.card.card_type];
          if (item.card[item.card.card_type].base_info.date_info.hasOwnProperty("end_timestamp")) {
            let cur = item.card[item.card.card_type].base_info.date_info.end_timestamp
            item.card[item.card.card_type].base_info.date_info.end_timestamp = util.formatTime(new Date(cur * 1000)) + "过期"
            item.hasTime = true;
          } else {
            //领取后当天生效30天有效
            //fixed_term
            let curfixed_term = item.card[item.card.card_type].base_info.date_info.fixed_term
            item.card[item.card.card_type].base_info.date_info.end_timestamp = `领取后当天生效${curfixed_term}天有效`;
            item.hasTime = false;
          }
        }),
          that.setData({
            "gList": res.data.data
          })
          
        // console.log(that.data.gList)
      }

    })
  },
  usecard:function(e){
    let cid = e.currentTarget.dataset.cid
    console.log(cid)
    wx.showToast({
      title: '前往卡包使用',
      icon: 'success',
      duration: 1500
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function (options) {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function (options) {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function (options) {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (options) {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {

  }
})



